<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FilterTable
      ref="table"
      height="auto"
      :columns="columns"
      :dataSource="tableList"
      :onSyncTableData="syncTableFun"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle">导入物料编码</multiuse-button>
        <multiuse-button size="small" type="primary" :click="deleteHandle">删 除</multiuse-button>
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="importsVisible" :title="'导入'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <importFilesT :rowData="formData" @close="importcloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { addSave } from '@/api/omSale/vehicleParameters/PlanOrderTime/index.js';
import { dictionary } from '@/utils/dictMixin';
import {importsExcel} from"../until/excel.js";
import importFilesT from './importFilesT';
export default {
  data() {
    // this.saveData = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTableT(),
      formData: {},
      importsVisible: false,
      tableList:[]
    };
  },
  mixins: [dictionary],

  components: {
    importFilesT,
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '物料编码信息',
        },
      ];
    },
    createdTableT() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '物料编码',
          dataIndex: 'materialCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '物料描述',
          dataIndex: 'materialDescription',
          width: 400,
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车型名称',
          dataIndex: 'vehicleModelName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '配置名称',
          dataIndex: 'configurationName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '选装名称',
          dataIndex: 'optionalName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '内饰',
          dataIndex: 'interior',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '外饰',
          dataIndex: 'exterior',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },

    addHandle() {
      this.importsVisible = true;
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let res = await addSave(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success',
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      }
    },
    importcloseHandler(val) {
      this.importsVisible = false;
      if(val.length>0) {
      this.tableList.concat(val)
      }
    }
  },
};
</script>
